package com.zhxh.nzpos.member;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;

import com.zhxh.nzpos.BaseActivity;
import com.zhxh.nzpos.Constants;
import com.zhxh.nzpos.R;
import com.zhxh.nzpos.dao.CardDao;
import com.zhxh.nzpos.dao.MemberDao;
import com.zhxh.nzpos.model.Card;
import com.zhxh.nzpos.model.Member;
import com.zhxh.nzpos.utils.ViewUtil;

/**
 * 会员管理--会员激活界面
 * 
 * @author wangzt
 * 
 */
public class ActiveMemberActivity extends BaseActivity {
	private EditText idET;
	EditText cardET;
	MemberDao memberDao;
	CardDao cardDao;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_member_active);
		memberDao = new MemberDao(this);
		cardDao = new CardDao(this);
		initViews();
	}

	private void initViews() {
		Intent intent = getIntent();
		String card = intent.getStringExtra(Constants.MEMBER_CARD);
		cardET = (EditText) findViewById(R.id.member_card_et);
		cardET.setText(card);

		idET = (EditText) findViewById(R.id.id_number_et);

		ImageView activeBtn = (ImageView) findViewById(R.id.member_active_btn);
		activeBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO
				if (idET.getText().toString().length() == 0) {
					idET.setError("身份证号不能为空");
					return;

				}
				Member member = memberDao.findMemberByShfzId(idET.getText()
						.toString());
				if (member == null) {
					ViewUtil.makeToast(ActiveMemberActivity.this,
							"信息库中没有身份信息，请先录入身份信息");
					return;
				}
				Card card = new Card();
				card.setCardNumber(cardET.getText().toString());
				card.setId(member.getCardId());
				// memberDao.
				int count = cardDao.active(card);
				if (count > 0) {
					ViewUtil.makeToast(ActiveMemberActivity.this, "卡激活成功!");
					finish();
				}

				else {
					ViewUtil.makeToast(ActiveMemberActivity.this,
							"卡激活失败，请检查身份录入信息是否正确!");
				}

			}
		});

		ImageView cancelBtn = (ImageView) findViewById(R.id.active_cancel_btn);
		cancelBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
	}
}
